home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Science / RLaB / help / MATRICES < prev    next >
Text File  |  1994-04-25  |  5KB  |  207 lines

  1. MATRIX:
  2.  
  3.     The MATRIX object is the fundamental data object in RLaB.
  4.     Matrices are dynamic data structures that can be created,
  5.     enlarged, or destroyed by the user. Matrices can be real or
  6.     complex numeric.
  7.  
  8.     Creating a matrix interactively is simple:
  9.  
  10.     m = [1,2,3;4,5,6;7,8,9];
  11.  
  12.     or
  13.  
  14.     m = [1,2,3;
  15.          4,5,6;
  16.          7,8,9]
  17.  
  18.     or
  19.  
  20.     m=[1,2,3;4,5,...
  21.        6;7,8,9]
  22.  
  23.     As you can see the syntax is similar to MATLAB, except you
  24.     cannot leave out the commas. However, you can break the line
  25.     at the semicolon, but ONLY at the semicolon, and the semicolon
  26.     cannot be left out.
  27.  
  28.     Matrices can be composed of other scalars, vectors and
  29.     matrices...
  30.  
  31.     > s = 1;
  32.     > v = 4:6;
  33.     > m = [s, 2, 3; v]
  34.      m =
  35.      matrix columns 1 thru 3
  36.                1           2           3
  37.                4           5           6
  38.  
  39.     To extract, or assign to matrix elements:
  40.  
  41.     > m[1;1]
  42.                1
  43.     > m[1;1] = 100
  44.      m =
  45.      matrix columns 1 thru 3
  46.              100           2           3
  47.                4           5           6
  48.  
  49.     When assigning values to matrix elements index checking is
  50.     automatically performed. When an index value exceeds the
  51.     dimension of the matrix, the size of the matrix is
  52.     automatically extended to accommodate the new value.
  53.  
  54.     clear(m);
  55.     m[1;1] = 10;
  56.  
  57.     Then the variable is automatically converted to a matrix
  58.     object, and sized appropriately.
  59.  
  60.     The following works, but is very inefficient:
  61.  
  62.     for(i in 1:4) {
  63.       for(j in 1:4) {
  64.         a[i;j] = i+j;
  65.       }
  66.     }
  67.  
  68.     since we are constantly extending the size of the matrix.
  69.     However, it is very convenient.
  70.  
  71.     Vectors can be used as matrix index values:
  72.  
  73.     > a=[1,2,3,4;5,6,7,8;9,10,11,12]
  74.      a =
  75.      matrix columns 1 thru 4
  76.                1           2           3           4
  77.                5           6           7           8
  78.                9          10          11          12
  79.  
  80.     > a[2,3;2,3]
  81.      matrix columns 1 thru 2
  82.                6           7
  83.               10          11
  84.  
  85.     > a[2;]
  86.      matrix columns 1 thru 4
  87.                5           6           7           8
  88.  
  89.     > a[;2]
  90.      matrix columns 1 thru 1
  91.                2
  92.                6
  93.               10
  94.     
  95.     > a[;2] = 200,600,1000
  96.      a =
  97.      matrix columns 1 thru 4
  98.                1         200           3           4
  99.                5         600           7           8
  100.                9       1e+03          11          12
  101.  
  102.     Matrix properties can be obtained from functions such as:
  103.     class(), type(), and size(). Additionally they can be obtained
  104.     by using the LIST-like syntax to reference the data:
  105.  
  106.     > m=[1,2,3;4,5,6;7,8,9;10,11,12]
  107.      m =
  108.      matrix columns 1 thru 3
  109.                1           2           3
  110.                4           5           6
  111.                7           8           9
  112.               10          11          12
  113.     > m.class
  114.     num
  115.     > m.type
  116.     real
  117.     > m.nr
  118.             4
  119.     > m.nc
  120.             3
  121.     > m.n
  122.            12
  123.     > show ( m )
  124.        name:      m     
  125.        class:     num   
  126.        type:      real  
  127.          nr:      4     
  128.          nc:      3     
  129.  
  130.     The show() function shows all of the available entity
  131.     information as once.
  132.  
  133.     Matrices can also be used like single dimension arrays. Any
  134.     matrix can be indexed with a single dimension `m[i]'. The
  135.     effect is to walk the matrix in a column fashion, thus:
  136.  
  137.     > m
  138.      m =
  139.      matrix columns 1 thru 3
  140.                1           2           3
  141.                4           5           6
  142.                7           8           9
  143.               10          11          12
  144.     > m[1]
  145.                1
  146.     > m[2]
  147.                4
  148.     > m[3]
  149.                7
  150.  
  151.     Matrices can also be forced into the shape of a column vector
  152.     with the `[:]' operator.
  153.  
  154.     > m[:]
  155.      matrix columns 1 thru 1
  156.             1  
  157.             4  
  158.             7  
  159.            10  
  160.             2  
  161.             5  
  162.             8  
  163.            11  
  164.             3  
  165.             6  
  166.             9  
  167.            12  
  168.  
  169.     ================================================================
  170.  
  171.      String Matrices:
  172.  
  173.     Strings matrices, belong to the string class, and not the
  174.     numeric class. String matrices have a different internal
  175.     representation than numeric matrices. String matrices can not
  176.     be operated on with numeric matrices, or in the same fashion.
  177.  
  178.     The individual members are the same as RLaB's scalar string
  179.     object. The syntax for creating a string matrix is the same as
  180.     a numerical matrix, except the elements are strings, and not
  181.     numbers.
  182.  
  183.     > sm = [ "s-element-1,1", "s-element-1,2";
  184.     >        "s-element-2,1", "s-element-2,2"]
  185.      sm =
  186.     s-element-1,1  s-element-1,2  
  187.     s-element-2,1  s-element-2,2  
  188.  
  189.     > sm[1;2]
  190.     s-element-1,2
  191.     > sm[3]
  192.     s-element-1,2
  193.  
  194.     > show ( sm )
  195.        name:      sm      
  196.        class:     string  
  197.        type:              
  198.          nr:      2       
  199.          nc:      2       
  200.  
  201.     > show ( sm[1;1] )
  202.        name:      NULL    
  203.        class:     string  
  204.         type:             
  205.          nr:      1       
  206.          nc:      1       
  207.